﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LeePong.Game.Shapes
{
    public class Rectangle
    {
        public int Width { get; set; }
        public int Height { get; set; }

        public float Left { get { return Coord.X; } }

        public float Top { get { return Coord.Y; } }

        public float Right { get { return Coord.X + Width; } }

        public float Bottom { get { return Coord.Y + Height; } }

        public float CenterX
        {
            get
            {
                return Coord.X + (Width / 2);
            }
            set
            {
                Coord.X = value - (Width / 2);
            }
        }

        public float CenterY
        {
            get
            {
                return Coord.Y + (Height / 2);
            }
            set
            {
                Coord.Y = value - (Height / 2);
            }
        }


        public Coordinates Coord { get; set; }

        public Rectangle()
        {
            this.Coord = new Coordinates();
        }
        public Rectangle(float x, float y, int width, int height)
            : this()
        {
            this.Coord.X = x;
            this.Coord.Y = y;
            this.Width = width;
            this.Height = height;
        }

        public Rectangle(Rectangle rectangle)
            : this(rectangle.Coord.X, rectangle.Coord.Y, rectangle.Width, rectangle.Height)
        {

        }

        public bool Contains(Coordinates coord)
        {
            return this.Contains(coord.X, coord.Y);
        }

        public bool Contains(float x, float y)
        {
            return this.Coord.X <= x && x < this.Coord.X + this.Width && this.Coord.Y <= y && y < this.Coord.Y + this.Height;
        }

        public bool IntersectsWith(Rectangle rect)
        {
            return rect.Coord.X < this.Coord.X + this.Width && this.Coord.X < rect.Coord.X + rect.Width && rect.Coord.Y < this.Coord.Y + this.Height && this.Coord.Y < rect.Coord.Y + rect.Height;
        }

    }
}
